<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主页</title>
    <style>
        canvas{
            display: block;
            margin: auto;
            background: #aaa;
        }
        .out{
            width: 300px;
            height: 15px;
            padding: 2px;
            border-radius: 5px;
            border: 1px solid #486;
        }
        .in{
            height: 100%;
            width:100%;
            border-radius: 10px;
        }
        .blood div{
            background-color: #911;
        }
        .power div{
            background-color: #119;
        }
        #info{
            width:100%;
        }
        #kill,#died{
            width: 50%;
            display: inline-block;
            text-align: center;
        }
        #ranking,#msg{
            position: absolute;
            left:0;
            top:0;
            font-size: .5em;
        }
    </style>
</head>
<body>
<script>
    function ajax(text,callback){
        var XHR=null;
        if (window.XMLHttpRequest) {
            // 非IE内核
            XHR = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            // IE内核,这里早期IE的版本写法不同,具体可以查询下
            XHR = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            XHR = null;
        }

        if(XHR){
            XHR.open("GET", text);

            XHR.onreadystatechange = function () {
                // readyState值说明
                // 0,初始化,XHR对象已经创建,还未执行open
                // 1,载入,已经调用open方法,但是还没发送请求
                // 2,载入完成,请求已经发送完成
                // 3,交互,可以接收到部分数据

                // status值说明
                // 200:成功
                // 404:没有发现文件、查询或URl
                // 500:服务器产生内部错误
                if (XHR.readyState == 4 && XHR.status == 200) {
                    // 这里可以对返回的内容做处理
                    // 一般会返回JSON或XML数据格式
//                    console.log(XHR.responseText);
                    callback(XHR.responseText);
                    // 主动释放,JS本身也会回收的
                    XHR = null;
                }
            };
            XHR.send();
        }
    }
    var names=["李狗蛋","赵日天","风车车","假老练","王大锤","两包辣条",
        "半包辣条","二师兄","史蒂芬霍金","我要上天","大力金刚腿","就是牛逼","吹个气球",
        "瘫痪病人","拉轰","一表人才","无限循环","葬爱家族","夺命之锤","衣冠禽兽"];
    var Name;
    function GetName(msg){
        if(typeof msg=="object")
        msg="写上你的大名";
        Name=prompt(msg,names[Math.floor(Math.random()*names.length)]);
        ajax("/getName?name="+Name,function(o){
            if(o!=1){
                GetName(o);
            }else{
                start();
            }
        })
    }
    window.onload=GetName;
</script>
<canvas id="game"></canvas>
<div style="width:300px;margin: auto">
    <div class="out blood">
        <div class="in" id="health">

        </div>
    </div>
    <div class="out power">
        <div class="in" id="power">

        </div>
    </div>
    <div id="info">
        <div id="kill">

        </div>
        <div id="died">

        </div>
    </div>
</div>
<div id="ranking"></div>
<div id="msg"></div>


<script src="js/Tool.js"></script>
<script src="js/main.js"></script>
<script src="js/person.js"></script>
<script src="js/img.js"></script>
<script src="js/webSocket.js"></script>
<script src="js/Bullet.js"></script>
<script src="js/Wall.js"></script>
</body>
</html>